package com.chalk.common.constant;

/**
 * @author xiaoqiang
 * @Description 返回结果 constants
 * @date 2019/3/21 16:51
 */
public class ResultConstants {

    /**
     * token失效code
     */
    public static final int TOKEN_INVALID_CODE = 101;

    /**
     * 调用结果(-1 异常 0 失败 1 成功)
     */
    public enum CallResult {
        /**
         * 异常
         */
        ERROR(-1, "异常"),
        /**
         * 失败
         */
        FAIL(0, "失败"),
        /**
         * 成功
         */
        SUCCESS(1, "成功");
        /**
         * code码
         */
        private Integer code;
        /**
         * 提示信息
         */
        private String msg;

        private CallResult(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public Integer getCode() {
            return code;
        }

        public String getMsg() {
            return msg;
        }
    }

    /**
     * 根据value返回枚举类型
     *
     * @param value
     * @return
     */
    public static CallResult getCallResult(Integer value) {
        for (CallResult callResult : CallResult.values()) {
            if (callResult.code.equals(value)) {
                return callResult;
            }
        }
        return null;
    }

}

